<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑文章</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__CSS__/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__CSS__/animate.min.css" rel="stylesheet">
    <link href="__CSS__/style.min.css?v=4.1.0" rel="stylesheet">
    <link href="__JS__/plugins/bootstrap-tagsinput/bootstrap-tagsinput.css" rel="stylesheet">
    <link href="__JS__/layui/css/layui.css"rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-10">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑文章</h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="commentForm" method="post" action="{:url('activity/successedit')}">
                        <input type="hidden" name="id" value="{$activity['id']}"/>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">成功故事标题：</label>
                            <div class="input-group col-sm-7">
                                <input id="title" type="text" class="form-control" name="title" required="" aria-required="true" value="11">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">活动地点：</label>
                            <!-- <div class="input-group col-sm-7">
                                <textarea id="description" class="form-control" name="description" required="" aria-required="true">111</textarea>
                            </div> -->
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-3">
                                    <label>省：</label>
                                    <select name="province" id="province" class="form-control">
                                        {volist name="area" id="vo"}
                                        {if condition="$vo['area_id'] eq $activity['province']"}
                                            <option selected="selected" value="{$vo.area_id}">{$vo.area_name}
                                            </option>
                                        {elseif condition="$vo['area_id'] neq $activity['province']" /}
                                        <option value="{$vo.area_id}">{$vo.area_name}
                                            </option>
                                        {/if}
                                        {/volist}
                                    </select>
                                </div>
                                <div class="col-sm-3">
                                    <label>市：</label>
                                    <select name="city" id="city" class="form-control">
                                    </select>
                                </div>
                            </div>
                        </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">活动内容</label>
                            <div class="input-group col-sm-4">
                                <textarea name="introduce" placeholder="请输入内容" rows="10" cols="80" class="layui-textarea">
                                <!-- <textarea rows="10" cols="80" id="introduce" aria-required="true"  class="form-control"> -->
                                   {$activity.introduce}
                                <!-- <input id="starttime" type="textarea" class="form-control" name="starttime" required="" aria-required="true" value="">{$activity.introduce} -->
                                    </textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">相处开始时间</label>
                            <div class="input-group col-sm-4">
                                <input id="starttime" type="text" class="form-control" name="starttime" required="" aria-required="true" value="{$activity.starttime|date='y-m-d',###}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">牵手成功时间</label>
                            <div class="input-group col-sm-7">
                                <input id="endtime" class="form-control" name="endtime" required="" aria-required="true" value="{$activity.endtime|date='y-m-d',###}">
                            </div>
                        </div>
                        <!-- <div class="form-group">
                            <label class="col-sm-3 control-label">活动时间</label>
                            <div class="input-group col-sm-7">
                                <input id="time" class="form-control"  required="" aria-required="true" name="time" value="{$activity.time|date='y-m-d',###}">
                            </div>
                        </div> -->
                        <div class="form-group">
                            <label class="col-sm-3 control-label">活动图片：</label>
                            <input name="pic" id="pic" type="hidden" value="{$activity['pic']}"/>
                            <div class="form-inline">
                                <div class="input-group col-sm-2">
                                    <button type="button" class="layui-btn" id="test1">
                                        <i class="layui-icon">&#xe67c;</i>上传图片
                                    </button>
                                </div>
                                <div class="input-group col-sm-3">
                                    <div id="sm">
                                        <img src="{$activity['pic']}" width="40px" height="40px"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">活动内容：</label>
                            <div class="input-group col-sm-7">
                                <script id="container" name="content" type="text/plain">
                                    {$activity['content']}
                                </script>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-8">
                                <!--<input type="button" value="提交" class="btn btn-primary" id="postform"/>-->
                                <button class="btn btn-primary" type="submit">确认提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="__JS__/jquery.min.js?v=2.1.4"></script>
<script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
<script src="__JS__/content.min.js?v=1.0.0"></script>
<script src="__JS__/plugins/bootstrap-tagsinput/bootstrap-tagsinput.min.js"></script>
<script src="__JS__/plugins/validate/jquery.validate.min.js"></script>
<script src="__JS__/plugins/validate/messages_zh.min.js"></script>
<script src="__JS__/layui/layui.js"></script>
<script src="__JS__/jquery.form.js"></script>
<script src="__JS__/plugins/ueditor/ueditor.config.js"></script>
<script src="__JS__/plugins/ueditor/ueditor.all.js"></script>
<script>
    layui.use('laydate', function(){
  var laydate = layui.laydate;
  
  //执行一个laydate实例
  laydate.render({
    elem: '#starttime', //指定元素
  });
  laydate.render({
    elem: '#endtime', //指定元素
  });
  laydate.render({
    elem: '#time', //指定元素
  });
});
</script>
<script type="text/javascript">
function getSelectVal(val,next,area) {
//获取后台json数据
    $.getJSON("/activity/ceshi", {
        bigname: val
    }, function(json) {
        var smallname = $("#"+next);
        $.each(json, function(index, array) {
            if(array['area_id'] == area){
                var option = "<option selected = \"selected\" value='" + array['area_id'] + "'>" + array['area_name'] + "</option>";
            }else{
                var option = "<option value='" + array['area_id'] + "'>" + array['area_name'] + "</option>";
            }
            smallname.append(option);
        });
    });
}

function getSelectVal1(area) {
//获取后台json数据
    $.getJSON("/activity/ceshi", {
        bigname: $("#province").val()
    }, function(json) {
        var smallname = $("#city");
        $("option", smallname).remove(); //清空原有的选项 
        $.each(json, function(index, array) {
            if(array['area_id'] == area){
                var option = "<option selected = \"selected\" value='" + array['area_id'] + "'>" + array['area_name'] + "</option>";
            }else{
                var option = "<option value='" + array['area_id'] + "'>" + array['area_name'] + "</option>";
            }
            smallname.append(option);
        });
    });
}

// 选择上级菜单选项触发事件
$(function() {
    getSelectVal1({$activity['city']});
    $("#province").change(function() {
        getSelectVal1({$activity['city']});
    });
});
</script>
<script type="text/javascript">

    var index = '';
    function showStart(){
        index = layer.load(0, {shade: false});
        return true;
    }

    function showSuccess(res){

        layer.ready(function(){
            layer.close(index);
            if(1 == res.code){
                layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
                    window.location.href = res.data;
                });
            }else if(111 == res.code){
                window.location.reload();
            }else{
                layer.msg(res.msg, {anim: 6});
            }
        });
    }

    $(document).ready(function(){
        // 添加角色
        var options = {
            beforeSubmit:showStart,
            success:showSuccess
        };

        $('#commentForm').submit(function(){
            $(this).ajaxSubmit(options);
            return false;
        });

        $('#price').tagsinput('add', 'some tag');
        $(".bootstrap-tagsinput").addClass('col-sm-12').find('input').addClass('form-control')
            .attr('placeholder', '输入后按enter');

        // 上传图片
        layui.use('upload', function(){
            var upload = layui.upload;

            //执行实例
            var uploadInst = upload.render({
                elem: '#test1' //绑定元素
                ,url: "{:url('activity/uploadImg')}" //上传接口
                ,done: function(res){
                    //上传完毕回调
                    $("#pic").val(res.data.src);
                    $("#sm").html('<img src="' + res.data.src + '" style="width:40px;height: 40px;"/>');
                }
                ,error: function(){
                    //请求异常回调
                }
            });
        });

        var editor = UE.getEditor('container');
    });

    // 表单验证
    $.validator.setDefaults({
        highlight: function(e) {
            $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
        },
        success: function(e) {
            e.closest(".form-group").removeClass("has-error").addClass("has-success")
        },
        errorElement: "span",
        errorPlacement: function(e, r) {
            e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
        },
        errorClass: "help-block m-b-none",
        validClass: "help-block m-b-none"
    });
</script>
</body>
</html>
